package trash;

import java.util.Iterator;

/**
 * @author  cpp
 */
public abstract class AICustomIterator<T> implements Iterator<T> {

	/**
	 * @uml.property  name="threadSet"
	 * @uml.associationEnd  
	 */
	private AIThreadSet<T> threadSet;
	/**
	 * @uml.property  name="index"
	 */
	private int index = -1;
	/**
	 * @uml.property  name="thread"
	 */
	private Thread thread;
	
	public AICustomIterator(AIThreadSet<T> threadSet) {
		this.threadSet = threadSet;
		this.thread = Thread.currentThread();
		this.threadSet.addIterator(this);
	}
	
	/**
	 * @return
	 * @uml.property  name="threadSet"
	 */
	public AIThreadSet<T> getThreadSet() {
		return this.threadSet;
	}

	protected void lockRecord(int index) throws InterruptedException  {
		this.threadSet.lockRecord(this, index);
	}
	
	public abstract boolean hasNext(); 

	public abstract T next();

	public void remove() {
		
	}

	/**
	 * @return
	 * @uml.property  name="index"
	 */
	public int getIndex() { 
		return this.index; 
	}	
	
	/**
	 * @param index
	 * @uml.property  name="index"
	 */
	protected void setIndex(int index) {
		this.index = index;
	}
	
	/**
	 * @return
	 * @uml.property  name="thread"
	 */
	public Thread getThread() {
		return this.thread;
	}
	
}	
